<%--
  Created by IntelliJ IDEA.
  User: Snakewood
  Date: 2020/12/25
  Time: 10:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>商品详情</title>
    <style type="text/css">
        div{
            width: 100%;
        }
    </style>
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script>
        $(document).ready(function(){
//获得文本框对象
            var t = $("#text_box");
//初始化数量为1,并失效减
            $('#min').attr('disabled',true);
            //数量增加操作
            $("#add").click(function(){
                // 给获取的val加上绝对值，避免出现负数
                t.val(Math.abs(parseInt(t.val()))+1);
                if (parseInt(t.val())!=1){
                    $('#min').attr('disabled',false);
                };
            })
            //数量减少操作
            $("#min").click(function(){
                t.val(Math.abs(parseInt(t.val()))-1);
                if (parseInt(t.val())==1){
                    $('#min').attr('disabled',true);
                };
            })
            $("#orderNum").click(function () {
                var x;
                x = parseInt(t.val());
                if (isNaN(x) || x<1 ){
                    alert("输入有误！请重新输入！");
                    return false;
                }else if (x >${cart.stock}){
                    alert("购买数量超过库存数量！请重新输入！");
                    return false;
                }
            })

        });
    </script>
</head>

<body style="text-align: center">

<%@include file="head.jsp"%>

<div style="text-align: center; margin: auto">
    <table border="1"     cellspacing="0"    bordercolor="#00CCCC" style="text-align: center">
        <tr>
            <td rowspan="7"><img src="${cart.cpic}" style="width: 350px;height: 350px;"></td><td>零食名称</td><td>${cart.cfname}</td>
        </tr>
        <tr>
            <td>零食信息</td><td>${cart.cfinfo}</td>
        </tr>
        <tr>
            <td>价格</td><td>${cart.cprice}元/${cart.cunit}</td>
        </tr>
        <tr>
            <td>口味</td><td>${cart.cflavor}</td>
        </tr>
        <tr>
            <td>库存${cart.isbuy==true}||${cart.isbuy==false}</td><td>${cart.stock}</td>
        </tr>
    </table>
    <c:choose>
        <c:when test="${cart.isbuy==false}">
                <form action="cart?op=alertGoodsNum" method="post">
        </c:when>
        <c:when test="${cart.isbuy==true}">
                <form action="cart?op=jixuaddGoodsToCart" method="post">
        </c:when>
    </c:choose>

        购买数量:
        <input id="min" name="" type="button" value="-" />
        <input id="text_box" name="number" type="text" value="${cart.number}" style="width:120px;text-align: center"/>
        <input id="add" name="" type="button" value="+" />  <br>
        <input type="submit" id="orderNum" value="加入购物车">
    </form>
</div>
</body>
</html>
